﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class usercontrols_ucCategoryMenu : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        show();
    }
    void show()
    {
        ThucDon cat = new ThucDon();
        Functions fnc = new Functions();
        DataTable Categories = cat.AllMenu();
        dvcat.Controls.Clear();
        Table tblCategories = new Table();
        tblCategories.CssClass = "menu_box_left";
        tblCategories.CellPadding = 0;
        tblCategories.CellSpacing = 0;
        tblCategories.Style.Add("width", "100%");
        TableRow nr = new TableRow();
        nr = fnc.NewRow(new object[] { "<a href=DanhMucThucDon.aspx>DANH MỤC THỰC ĐƠN </a>" }, new string[] { "100%" }, new string[] { "left" }, new int[] { 2 }, 24, new string[] { "" }, "box_left_top");
        tblCategories.Rows.Add(nr);
        if (Categories.Rows.Count > 0)
        {
            string space = "&nbsp;&nbsp;";
            string img = "<img src=\"images/none.gif\" alt=\"\" width=\"1\" height=\"1\" />";
            foreach (DataRow row in Categories.Rows)
            {

                string str = "<a href=\"ChitietThucDon.aspx?maSanPham=" + row["MenuId"] + "\">" + row["name"].ToString() + "</a> ";
                nr = fnc.NewRow(new object[] { img, str }, new string[] { "10px", "193px" }, 20, new string[] { "", "menu_item_left" });
                tblCategories.Rows.Add(nr);

            }
        }

        //nr = new TableRow();
        //nr = fnc.NewRow(new string[] { "<img src=\"images/menu_bottom_left.gif\" alt=\"\" width=\"203\" height=\"24\"/>" }, new string[] { "10%" }, new string[] { "" }, new int[] { 2 }, 24, new string[] { "" }, "");
        //tblCategories.Rows.Add(nr);
        dvcat.Controls.Add(tblCategories);
    }

    void Addrow(ref string str, DataTable dtb, string space, string id, Functions fnc)
    {
        foreach (DataRow row in dtb.Rows)
        {
            if (row["parents_id"].ToString() == id && row["id"].ToString() != id)
            {
                string temp = space + "&nbsp;&nbsp;&nbsp;";
                str += "<tr><td class=\"menu_sub_item_left\"><a href=\"#cat" + row["id"].ToString() + "\" onclick=\"getAuctions(" + row["id"].ToString() + ")\" >" + row["name"].ToString() + "</a></td></tr>";
                Addrow(ref str, dtb, temp, row["id"].ToString(), fnc);

            }
        }
    }
}
